package pATT.core.visual;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.Panel;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

import pATT.core.Utils;


public class ResolutionImage extends JDialog {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int JHEIGHT = 1024;
	private static final int JWIDHT = 768;
	private Panel panel = null;
	private Panel panel1 = null;
	private JButton jButton = null;
	private JLabel jLabelHeight = null;
	private JLabel jLabelWidht = null;
	private JTextField jTextFieldHeigth = null;
	private JTextField jTextFieldWidth = null;
	private JLabel jLabelText = null;
	public ResolutionImage() throws HeadlessException {
		super();
		// TODO Auto-generated constructor stub
		initialize();
	}
	/**
	 * This method initializes panel	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanel() {
		if (panel == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			panel = new Panel();
			panel.setLayout(gridLayout);
			panel.add(getPanel1(), null);
		}
		return panel;
	}
	
	/**
	 * This method initializes panel1	
	 * 	
	 * @return java.awt.Panel	
	 */
	private Panel getPanel1() {
		if (panel1 == null) {
			jLabelText = new JLabel();
			jLabelText.setBounds(new java.awt.Rectangle(-1,7,222,28));
			jLabelText.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jLabelText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabelText.setText("Set parameters for Image Resolution");
			jLabelWidht = new JLabel();
			jLabelWidht.setBounds(new java.awt.Rectangle(21,88,49,27));
			jLabelWidht.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabelWidht.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jLabelWidht.setText("Width");
			jLabelHeight = new JLabel();
			jLabelHeight.setBounds(new java.awt.Rectangle(21,45,49,27));
			jLabelHeight.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabelHeight.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jLabelHeight.setText("Heigth");
			panel1 = new Panel();
			panel1.setLayout(null);
			panel1.add(getJButton(), null);
			panel1.add(jLabelHeight, null);
			panel1.add(jLabelWidht, null);
			panel1.add(getJHeigth(), null);
			panel1.add(getJWidth(), null);
			panel1.add(jLabelText, null);
		}
		return panel1;
	}
	
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new java.awt.Rectangle(81,132,66,24));
			jButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jButton.setText("OK");
			jButton.setBackground(java.awt.SystemColor.control);
			jButton.addActionListener(new java.awt.event.ActionListener() {   
				public void actionPerformed(java.awt.event.ActionEvent e) {    
					if(getJHeigth().getText().trim().equals("") || Utils.stringToInt(getJHeigth().getText().trim(),32000) == -1){
						getJHeigth().setText(""+ResolutionImage.JHEIGHT);
					}
					if(getJWidth().getText().trim().equals("") || Utils.stringToInt(getJWidth().getText().trim(),32000) == -1){
						getJWidth().setText(""+ResolutionImage.JWIDHT);
					}
					
					dispose();
					int heigth = Integer.parseInt(getJHeigth().getText().trim());
					int width = Integer.parseInt(getJWidth().getText().trim());
					//llama para almacenar la imagen
					UserProfilingUI.eINSTANCE.getVisualizePanel().saveImage(heigth, width);
				}
				
			});
		}
		return jButton;
	}
	
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setAlwaysOnTop(true);
		this.setModal(true);
		this.setSize(228, 208);
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension freim = this.getSize();
		if (pantalla.width < freim.width){
			freim.width = pantalla.width;
		}
		if (pantalla.height < freim.height) {
			freim.height = pantalla.height;
		}
		this.setLocation((pantalla.width-freim.width)/2,(pantalla.height-freim.height)/2);
		
		this.setContentPane(getPanel());
		this.setTitle("Image Resolution");
		
	}
//	@SuppressWarnings("deprecation")
//	public static void main(String[] args) {
//	new About().show();
//	}
	/**
	 * This method initializes jTextFieldHeigth	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJHeigth() {
		if (jTextFieldHeigth == null) {
			jTextFieldHeigth = new JTextField();
			jTextFieldHeigth.setText(""+JHEIGHT);
			jTextFieldHeigth.setBounds(new java.awt.Rectangle(69,45,119,27));
		}
		return jTextFieldHeigth;
	}
	/**
	 * This method initializes jTextFieldWidth	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJWidth() {
		if (jTextFieldWidth == null) {
			jTextFieldWidth = new JTextField();
			jTextFieldWidth.setText(""+JWIDHT);
			jTextFieldWidth.setBounds(new java.awt.Rectangle(69,89,119,27));
		}
		return jTextFieldWidth;
	}
	public void setJHeigth(JTextField textFieldHeigth) {
		jTextFieldHeigth = textFieldHeigth;
	}
	public void setJWidth(JTextField textFieldWidth) {
		jTextFieldWidth = textFieldWidth;
	}
}  //  @jve:decl-index=0:visual-constraint="124,70"
